package test.script;

import com.cait.workflowserver.execution.FlowExecuteContext;
import com.cait.workflowserver.runtime.Server;

import test.WorkFlowTest;

public class testTextPars  extends WorkFlowTest{

	public testTextPars(String arg0) {
		super(arg0);
		// TODO 自动生成构造函数存根
	}
	
	
	public void testPars()
	{
		//executeMutilScriptText("rrree[#dddd#]pppp[#333r#]",null);
		FlowExecuteContext f=new FlowExecuteContext();
		//String s=Server.getInstance().getFlowScriptRunner().executeMutilScriptText("33[#3>0#]rrr[#\"eee\"#]", f);
		String s=Server.getInstance().getFlowScriptRunner().executeMutilScriptText("e33[#tt#]e22e[#3>0#]rrr[#\"http://yyy,l,lh,d\"#]gg33", f);
		System.out.println(s);
		
    	
	}
	
	public String executeMutilScriptText(String text, FlowExecuteContext context)
	{
		//java.util.ArrayList al=new java.util.ArrayList();
		java.lang.StringBuffer tsb=new java.lang.StringBuffer();
		if(text==null)
			return null;
		int len=text.length();
		for(int i=0;i<len;i++)
		{
			String s=String.valueOf(text.charAt(i));
			String sold=s;
            String s2=null;
            if(i+1<len)
            {
            	s2=String.valueOf(text.charAt(i+1));
            }
            if(s2!=null)
            	s=s+s2;
            if(s.equals("[#"))
            {
            	
            	System.out.println("找到[#");
            	if(i+2<len)
            	{
            		java.lang.StringBuffer tsb2=new java.lang.StringBuffer();
            		i+=parseText(text.substring(i),tsb2);
            	 	System.out.println("解析出:"+tsb2.toString());
            	}	
            	tsb.append(",");
            }
            else
            {
            	tsb.append(sold);
            }
		}
		System.out.println("结果"+tsb.toString());
		return null;
	}
	private int  parseText(String text,java.lang.StringBuffer tsb)
	{
		System.out.println("找到"+text);
		if(text==null)
			return 0;
		int len=text.length();
		for(int i=0;i<len;i++)
		{
			String s=String.valueOf(text.charAt(i));
			String sold=s;
            String s2=null;
            if(i+1<len)
            {
            	s2=String.valueOf(text.charAt(i+1));
            }
            if(s2!=null)
            	s=s+s2;
            if(!s.equals("#]"))
            {
            	tsb.append(sold);
            }
            else
            {
            	tsb.append(sold+"]");
            	return i+1;
            }
		}
		
		return 0;
	}

}
